local yicheng = fk.CreateSkill{
  name = "ld__yicheng",
}
local H = require "packages.ol_hegemony.util"

local yicheng_spec = {
  on_cost = function(self, event, target, player, data)
    return player.room:askToSkillInvoke(target, {skill_name = yicheng.name, prompt = "#ld__yicheng-ask::"..target.id })
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:doIndicate(player.id, {target.id})
    target:drawCards(1, yicheng.name)
    if not target.dead then
      room:askForDiscard(target, 1, 1, true, yicheng.name, false)
    end
  end
}

yicheng:addEffect(fk.TargetConfirmed, {
  anim_type = "defensive",
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(yicheng.name) and H.compareKingdomWith(target, player) and data.card.trueName == "slash"
    and not target.dead and (player:hasShownSkill(yicheng.name) or target == player)
  end,
  on_cost = yicheng_spec.on_cost,
  on_use = yicheng_spec.on_use
})
yicheng:addEffect(fk.TargetSpecified, {
  anim_type = "defensive",
  can_trigger = function (self, event, target, player, data)
    return player:hasSkill(yicheng.name) and H.compareKingdomWith(target, player) and data.card.trueName == "slash"
    and not target.dead and (player:hasShownSkill(yicheng.name) or target == player) and data.firstTarget
  end,
  on_cost = yicheng_spec.on_cost,
  on_use = yicheng_spec.on_use
})

yicheng:addTest(function (room, me)
  local sameKingdom = table.find(room.alive_players, function (p) return p ~= me and H.compareKingdomWith(p, me) end)
  if sameKingdom then
    FkTest.setNextReplies(me, {"1"})
    local comp2 = room.players[2]
    FkTest.runInRoom(function ()
      room:handleAddLoseSkills(me, yicheng.name)
      room:useVirtualCard("slash", nil, me, {comp2})
    end)

    FkTest.setNextReplies(me, {"1"})
    FkTest.runInRoom(function ()
      room:useVirtualCard("slash", nil, comp2, {sameKingdom})
    end)
  end
end)

Fk:loadTranslationTable{
  ["ld__yicheng"] = "疑城",
  [":ld__yicheng"] = "当一名与你势力相同的角色使用【杀】指定目标后，或成为【杀】的目标后，其可以摸一张牌，然后弃置一张牌。",

  ["#ld__yicheng-ask"] = "疑城：令 %dest 摸一张牌，然后弃置一张牌",

  ["$ld__yicheng1"] = "不怕死，就尽管放马过来！",
  ["$ld__yicheng2"] = "待末将布下疑城，以退曹贼。",
}

return yicheng
